// pages/orderform/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    userId: '',
    active: 0,
    userorder: {
      userlist: ''
    },
    username: '',
    payData: [],
    //所选状态
    numin: null,
    usersunm: {
      userdata: "",
      avimg: '',
      useid: '',
      addli: ''
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options.statet);
    this.setData({
      active:JSON.parse(options.statet||0)
    })
    if (options.statet == 0) {
      this.data.numin = null
    } else if (options.statet == 1) {
      this.data.numin = 0
    } else if (options.statet == 2) {
      this.data.numin = 1
    } else if (options.statet == 3) {
      this.data.numin = 2
    } else if (options.statet == 4) {
      this.data.numin = 3
    }
    console.log(this.data.active);
    //获取userinfo
    this.data.userinfo = wx.getStorageSync('userinfo')
    this.data.userId = wx.getStorageSync('userId')
    this.data.username = wx.getStorageSync('loginuser');
    this.getorderact()
    console.log(this.data.userinfo);
  },

  handlequxiao(e){
    const index= e.currentTarget.dataset['word'];
    console.log(index);
    wx.request({
      url: app.globalData.url+'/zkxj/order/delete',
      data: {
        "orderId": index,
      },
      method: 'GET',
      header: {
       'content-type': 'application/json',
        'token':wx.getStorageSync('token')
      },
      success: (res) => {
        console.log(res);
        if(res.data.code==0){
          wx.showToast({
            title: '取消成功',
            icon: 'succes',
            duration: 2000,
            mask: true
          })
          this.getorderact()
        }
      },
    })
  },
  //请求订单状态
  getorderact() {
    console.log(this.data.username);
    wx.request({
      url: app.globalData.url+'/zkxj/order/wechat/list',
      data: {
        "status": this.data.numin,
        "name": this.data.username.realName,
        "userId": this.data.userId,
        "nickname": this.data.userinfo.userInfo.nickName,
        "currPage": 1,
        "pageSize": 10
      },
      method: 'POST',
      header: {
       'content-type': 'application/json',
        'token':wx.getStorageSync('token')
      },
      success: (res) => {
        this.setData({
          userorder: {
            userlist: res.data.data
          }
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  onChange(event) {
    console.log(event.detail.index);
    if (event.detail.index == 0) {
      this.data.numin = null
    } else if (event.detail.index == 1) {
      this.data.numin = 0
    } else if (event.detail.index == 2) {
      this.data.numin = 1
    } else if (event.detail.index == 3) {
      this.data.numin = 2
    } else if (event.detail.index == 4) {
      this.data.numin = 3
    }
    this.getorderact()
    console.log(this.data.numin);

  },
  //去结算
  handletobuy() {
    var that = this.data
    if (this.data.payData.length == 0) {
      this.setData({
        showAddOrder: true
      });
      return
    }
    var sumMoney = that.numpr + that.numpt + that.pricenums //总价
    wx.navigateTo({
      url: `/pages/seaccounts/index?arr=${JSON.stringify(this.data.payData)}&sum=${JSON.stringify(sumMoney*this.data.play)}&type=2&upgradeLevel=0`
    })
    console.log(this.data.payData);

  },
  handlecheckco(e){
    const index= e.currentTarget.dataset['word'];
console.log(index);
wx.request({
  url: app.globalData.url+'/zkxj/order/confirm',
  data: {
    "orderId": index,
    
  },
  method: 'GET',
  header: {
   'content-type': 'application/json',
    'token':wx.getStorageSync('token')
  },
  success: (res) => {
    console.log(res);
    if(res.data.code==0){
      wx.showToast({
        title: '收货成功',
        icon: 'succes',
        duration: 2000,
        mask: true
      })
      this.getorderact()
    }
  },
})
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getorderact()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})